package com.example.chirdrenserver.controller.AdminController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.chirdrenserver.Authority.Authority;
import com.example.chirdrenserver.Pojo.dto.BasePage;
import com.example.chirdrenserver.Service.FileService;
import com.example.chirdrenserver.Utils.Result;
import com.example.chirdrenserver.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Yu
 * @Description //TODO $
 * @Date $ $
 **/
@RestController
@RequestMapping("/admin/file")
public class AdminFileController {

    @Autowired
    private FileService fileService;

    @GetMapping("/list")
    @Authority(authority= "permission:file")
    public Result getList(BasePage basePage) {
        List<Page> page = fileService.page(basePage.page()).getRecords();
        return Result.success(page);
    }

    @PostMapping("/id")
    @Authority(authority= "permission:file")
    public Result deleteFile(@PathVariable Integer id) {
        if (!fileService.removeById(id))
        {
            throw new BaseException("删除失败");
        }
        return Result.success();
    }
}
